<?php
class Database{

	private $db_server;
	private $db_user;
	private $db_password;
	private $db_name;
	private $db_connection;
	private $connected = false;
	
	public function __construct($Server,$User,$Password,$Name){
		$this->db_server = $Server;
		$this->db_user = $User;
		$this->db_password = $Password;
		$this->db_name = $Name;
	}
	public function connect(){
		try{
                    $this-> db_connection = mysql_connect($this->db_server,$this->db_user,$this->db_password,true);
                    mysql_select_db($this->db_name);
                    if(!$this-> db_connection){
                        throw new Exception("Błąd połączenia z bazą danych:" .mysql_error());
                    }else{
                        $this->connected = true;
                        mysql_query("SET NAMES utf8");
                        mysql_query("SET CHARACTER SET utf8");
                        mysql_query("SET collation_connection = utf8_polish_ci");
                    }
		}
		catch(Exception $e){
                    echo $e->getMessage();
                }
	}
        public function disconnect(){
 		if($this->connected){
			mysql_close($this->db_connection);
			$this-> connected = false;
		}else{
			return "Błąd. Nie nawiazano zadnego polaczenia z baza danych. Nie mozna zamknac polaczenia.";
		}
        }
}
?>